<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        #container {
            width: 900px;
            height: 430px;
            /* border: 1px solid; */
            display: flex;
            justify-content: space-between;
        }

        #left_photo,
        #right_photo {
            width: 430px;
            height: 430px;
            border: 1px solid;
        }

        ul {
            width: 430px;

            /* border: 1px solid; */
            list-style: none;
            display: flex;
            justify-content: space-around;
            margin-top: 10px;
        }

        li {
            width: 60px;
            height: 60px;
            border: 1px solid;

        }

        i {
            display: block;
            width: 231px;
            height: 231px;
            background-color: rgba(0, 255, 0, .3);
            position: absolute;
        }

        .none {
            display: none;

        }
    </style>
</head>

<body>
    <div id="container">
        <!-- 左边中图 -->
        <div id="left_photo">
            <!-- 矩形 -->
            <i class="none" id='square'></i>
        </div>
        <!-- 右边中图 -->
        <div id="right_photo"></div>
    </div>
    <!-- 小图 -->
    <ul id="ul">

    </ul>
    <script>
        const small_arr = ["./点击图片/小图（1）.jpg", "./点击图片/小图（2）.jpg", "./点击图片/小图（3）.jpg"];
        const middle_arr = ["./点击图片/大图（1）.jpg", "./点击图片/大图（2）.jpg", "./点击图片/大图（3）.jpg"];
        const large_arr = ["./点击图片/巨大图（1）.jpg", "./点击图片/巨大图（2）.jpg", "./点击图片/巨大图（3）.jpg"];

        function render() {
            ul.innerHTML = small_arr.map((item, index) => `<li><img src='${item}' data-id='${index}'></li>`).join('');
            left_photo.style.backgroundImage = `url(${middle_arr[0]})`
            right_photo.style.backgroundImage = `url(${large_arr[0]})`
        }
        render();
        ul.onmousemove = function (event) {
            if (event.target.nodeName == 'IMG') {
                let i = event.target.dataset.id
                left_photo.style.backgroundImage = `url(${middle_arr[i]})`
                right_photo.style.backgroundImage = `url(${large_arr[i]})`
            }
        }
        left_photo.onmouseenter = function () {
            square.classList.remove('none');
            right_photo.classList.remove('none');
        }
        left_photo.onmouseleave = function () {
            square.classList.add('none');
            right_photo.classList.add('none');
        }
        left_photo.onmousemove = function (event) {
            let x = event.clientX - container.offsetLeft - square.offsetWidth / 2;
            let y = event.clientY - container.offsetTop - square.offsetHeight / 2;
            x < 0 ? x = 0 : '';
            y < 0 ? y = 0 : '';
            if (x > left_photo.offsetWidth - square.offsetWidth) {
                x = left_photo.offsetWidth - square.offsetWidth
            }
            if (y > left_photo.offsetHeight - square.offsetHeight) {
                y = left_photo.offsetHeight - square.offsetHeight
            }


            console.log(x, y);
            square.style.cssText = `
                left: ${x}px;
                top: ${y}px;
            `;
            right_photo.style.cssText += `
            background-position: ${-x * 800 / 430}px ${-y * 800 / 430}px;
            `

        }
    </script>
</body>

</html>